#!/bin/bash

ensure_package() {
    local package_name=$1
    local package_version=$2

    if conda_run_cmd pip show "$package_name" &> /dev/null; then
        echo "$package_name is already installed"
    else
        echo "$package_name is not installed. Installing now..."

        if [ -n "$package_version" ]; then
            conda_run_pip_install "$package_name==$package_version"
        else
            conda_run_pip_install "$package_name"
        fi

        if conda_run_cmd pip show "$package_name" &> /dev/null; then
            echo "[INFO] Successfully installed $package_name"
        else
            echo "[ERROR] Failed to install $package_name"
            return 1
        fi
    fi
}

ensure_package modelscope

